﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;
using QASPRibbon;
using QASPRibbon.Controls;

namespace QASPRibbonDemo.MultiTabs
{
    [ToolboxItemAttribute(false)]
    public class MultiTabs : WebPart
    {
        protected override void CreateChildControls()
        {
            var tabs = GetTabs();
            foreach (var tab in tabs)
            {
                RibbonManager.Current.AddTabToPage(tab, Page);
            }
            var qat = new RibbonQAT
                {
                    Controls = new[]
                        {
                            new RibbonQATButton {Text = "dfdf"},
                            new RibbonQATButton
                                {
                                    Text = "Address book", 
                                    Location = RibbonQATLocation.Right,
                                    Width = new Unit("16px"),
                                    Height = new Unit("16px"),
                                    ImageUrl = SPUtility.ContextImagesRoot + "addressbook.png"
                                }
                        }
                };
                
            RibbonManager.Current.AddQATToPage(qat, Page);
        }

        private IEnumerable<RibbonTab> GetTabs()
        {
            var tab1 = new RibbonTab("Tab1", "Tab 1")
            {
                Sequence = 510
            };
            tab1.Groups = new[]
            {
                new RibbonGroup("g1", "Group 1")
                {
                    Sections = new []
                    {
                        new RibbonGroupSection
                        {
                            Type = RibbonSectionType.OneRow,
                            DisplayMode = RibbonDisplayMode.Image32AndCaption,
                            Controls = new RibbonControl[]
                            {
                                new RibbonButton("b1", "Button 1")
                                {
                                    OnClientClick = "alert('b1 has been clicked!')",
                                    Image = RibbonImageDefinition.Standard15(5, 5)
                                }
                            }
                        },
                        RibbonGroupSection.Divider,
                        new RibbonGroupSection
                        {
                            Type = RibbonSectionType.OneRow,
                            DisplayMode = RibbonDisplayMode.Image32AndCaption,
                            Controls = new RibbonControl[]
                            {
                                new RibbonButton("b5", "Button 5")
                                {
                                    OnClientClick = "alert('b5 has been clicked!')",
                                    Image = RibbonImageDefinition.Standard15(5, 5)
                                }
                            }
                        },
                        new RibbonGroupSection
                        {
                            Type = RibbonSectionType.ThreeRows,
                            DisplayMode = RibbonDisplayMode.Image16AndCaption,
                            Controls = new RibbonControl[]
                            {
                                new RibbonButton("b2", "Button 2") { Image = RibbonImageDefinition.Standard15(5, 5) },
                                new RibbonButton("b3", "Button 3") { Image = RibbonImageDefinition.Standard15(4, 5) },
                                new RibbonButton("b4", "Button 4") { Image = RibbonImageDefinition.Standard15(3, 5) }
                            }
                        }
                    }
                }
            };
            return new[] { tab1 };
        }

        private string[] _demoArray = new[]
                                          {
                                              "John H Hammergren", "Ralph Lauren", "Michael D Fascitelli",
                                              "Richard D Kinder",
                                              "David M Cote", "George Paz", "Jeffery H Boyd"
                                          };

        private IEnumerable<RibbonControl> _demoButtons()
        {
            var rnd = new Random();

            return _demoArray.Select(x => new RibbonButton(x.Replace(" ", string.Empty), x)
            {
                Image = RibbonImageDefinition.Standard(rnd.Next(5, 10), rnd.Next(5, 10)),
                OnClientClick = "alert('" + x + " has been clicked!');"
            }).Cast<RibbonControl>();
        }
    }
}
